package com.boot.cluster.worker.splitter;

import com.boot.cluster.worker.bean.TaskSplitterInfo;

import java.util.ArrayList;
import java.util.List;


public class RangeSplitter implements Splitter {
	/**
	 * 分片数量
	 */
	private int pieces;
	/**
	 * 起始
	 */
	private Long start;
	/**
	 * 截止
	 */
	private Long end;
	public RangeSplitter(int pieces,Long start,Long end) {
		this.pieces=pieces;
		this.start=start;
		this.end=end;
	}
	@Override
	public List<TaskSplitterInfo> excute(){
		List<TaskSplitterInfo> list= new ArrayList<>();
		double step = ((this.end - this.start) + 1) / (double) this.pieces;
		for (double i = this.start; i < this.end; i += step) {
			list.add(new TaskSplitterInfo(Math.round(i),Math.round((i + step) - 1)));
		}
		return list;
	}
}